package Maxmarry;

import java.util.Scanner;

public class max {
    public static int max(int[] nums) {

        int pre = 0;
        int summax = nums[0];
        for (int x : nums) {
            //pre来维护对于当前f(i)的f(i−1)的值是多少
            pre = Math.max(pre + x, x);//判断f(i-1)是否要加到当前数上
            summax = Math.max(summax, pre);//获取最大值
        }
        return summax;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number = Integer.parseInt(sc.next());
        //number表示数组的长度
        int[] num = new int[number];

        //对数组元素循环赋值
        for (int i = 0; i < number; i++) {
            num[i]=sc.nextInt();
        }
        System.out.println(max(num));
    }
}
